<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box" index="1"></div>
    <script>
        var box = document.querySelector("div");
        console.log(box.id);
        console.log(box.getAttribute("index"));
        box.id = "demo";
        console.log(box.id);
        box.setAttribute("id", "nihao");
        console.log(box.getAttribute("id"));
        box.className = "nn";
        console.log(box.id);
        box.removeAttribute("index");
    </script>
</body>

</html>